package com.serene.authority.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serene.authority.admin.entity.MyRoleMenu;
import com.serene.authority.admin.mapper.RoleMenuMapper;
import com.serene.authority.admin.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author serence
 * @date 2021/5/8 20:48
 */

@Service
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, MyRoleMenu> implements RoleMenuService {

    @Autowired
    private RoleMenuMapper roleMenuMapper;


    /**
     * 根据角色id删除角色菜单
     *
     * @param roleId 角色id
     * @return
     */
    @Override
    public Integer deleteRoleMenuByRoleId(Integer roleId) {
        QueryWrapper<MyRoleMenu> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id", roleId);
        return roleMenuMapper.delete(wrapper);
    }

    /**
     * 通过role_id计算权限数量
     *
     * @param menuId 菜单id
     * @return
     */
    @Override
    public Integer queryRoleMenuCountByMenuId(Integer menuId) {
        QueryWrapper<MyRoleMenu> wrapper = new QueryWrapper<>();
        wrapper.eq("menu_id", menuId);
        return roleMenuMapper.selectCount(wrapper);
    }

}
